// components/Keyboard/Keyboard.ts
Component({
  /**
   * 组件的属性列表
   */
  properties: {
    value: String,
    color: Object
  },

  /**
   * 组件的初始数据
   */
  data: {},

  /**
   * 组件的方法列表
   */
  methods: {
    // 输入
    handleInput(e: WechatMiniprogram.CustomEvent) {
      const { key } = e.currentTarget.dataset
      const { value } = this.properties
      var count = ((value + key).match(new RegExp('\\.', 'g')) || []).length
      if (count > 1) return
      this.setData({ value: value + key })
    },
    // 回退
    handleBack() {
      const value = this.properties.value
      this.setData({ value: value.substring(0, value.length - 1) })
    },
    // 确认
    handleSubmit() {
      const { value } = this.properties
      if (value) {
        this.triggerEvent('submit', { value })
      }
    }
  }
})
